package org.example.app.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * 内容排行榜结果实体类 - 符合实时数仓设计规范
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ContentRankResult extends BaseDwsBean {
    
    // 业务主键
    private String contentId;
    private String contentTitle;
    
    // 维度字段
    private String contentType;  // live、video、image
    private String shopId;
    private String shopName;
    private String categoryId;
    private String categoryName;
    
    // 流量度量字段
    private Long viewCount;
    private Long clickCount;
    private Long likeCount;
    private Long commentCount;
    private Long shareCount;
    private Double avgViewDuration;
    private Double clickRate;
    
    // 交易度量字段
    private Long orderCount;
    private Double totalSalesAmount;
    private Double conversionRate;
    private Long productSoldCount;
    
    // 互动度量字段
    private Long interactionCount;
    private Double engagementRate;
    
    /**
     * 计算点击率
     */
    public void calculateClickRate() {
        if (viewCount != null && viewCount > 0 && clickCount != null) {
            this.clickRate = clickCount.doubleValue() / viewCount.doubleValue() * 100;
        } else {
            this.clickRate = 0.0;
        }
    }
    
    /**
     * 计算转化率
     */
    public void calculateConversionRate() {
        if (clickCount != null && clickCount > 0 && orderCount != null) {
            this.conversionRate = orderCount.doubleValue() / clickCount.doubleValue() * 100;
        } else {
            this.conversionRate = 0.0;
        }
    }
    
    /**
     * 计算互动总数
     */
    public void calculateInteractionCount() {
        long interactions = 0;
        if (likeCount != null) interactions += likeCount;
        if (commentCount != null) interactions += commentCount;
        if (shareCount != null) interactions += shareCount;
        this.interactionCount = interactions;
    }
    
    /**
     * 计算互动率
     */
    public void calculateEngagementRate() {
        calculateInteractionCount();
        if (viewCount != null && viewCount > 0 && interactionCount != null) {
            this.engagementRate = interactionCount.doubleValue() / viewCount.doubleValue() * 100;
        } else {
            this.engagementRate = 0.0;
        }
    }
}